function decoded_seq = rs_decode_31_15(encoded_seq)
    % Check if the encoded sequence length is a multiple of 5
    if mod(length(encoded_seq), 5) ~= 0
        error('Encoded sequence length must be a multiple of 5');
    end
    
    % RS (31, 15) parameters
    n = 31;
    k = 15;
    
    % Number of bits per symbol
    bits_per_symbol = 5;
    
    % Convert encoded 01 sequence to symbols
    num_symbols = length(encoded_seq) / bits_per_symbol;
    symbols = zeros(1, num_symbols);
    for i = 1:num_symbols
        symbols(i) = bin2dec(num2str(encoded_seq((i-1)*bits_per_symbol+1:i*bits_per_symbol)));
    end
    
    % Number of blocks
    num_blocks = num_symbols / n;
    if mod(num_symbols, n) ~= 0
        error('Encoded sequence does not correspond to full RS (31, 15) codewords');
    end
    
    % Initialize decoded sequence
    decoded_seq = [];
    
    % Process each block
    for blk = 1:num_blocks
        start_idx = (blk-1)*n + 1;
        end_idx = blk*n;
        
        % Extract block of symbols
        block_symbols = symbols(start_idx:end_idx);
        
        % Convert to Galois field array
        gf_symbols = gf(block_symbols, bits_per_symbol);
        
        % Decode the block using rsdec
        [decoded_gf_symbols, cnumerr] = rsdec(gf_symbols, n, k);
        
        % Check for decoding errors
        if cnumerr > 0
            warning('Decoding block %d: %d errors corrected', blk, cnumerr);
        end
        
        % Convert decoded symbols to binary sequence and append to result
        for i = 1:length(decoded_gf_symbols)
            if decoded_gf_symbols.x(i) ~= 0
                decoded_seq = [decoded_seq, dec2bin(decoded_gf_symbols.x(i), bits_per_symbol) - '0'];
            end
        end
    end
end
